package com.trinhrae.shooting.handler;

import com.trinhrae.shooting.entity.BaseResponse;
import com.trinhrae.shooting.exception.BusinessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: TrinhRae
 * @Package: com.trinhrae.shooting.handler
 * @Project: shooting
 * @Date: 2025/9/3 9:33
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> handleBusinessException(BusinessException e) {
        return BaseResponse.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public BaseResponse<?> handleException(Exception e) {
        return BaseResponse.error(500, "系统错误，请联系管理员");
    }
}
